﻿var winState = "0";

Ext.onReady(function () {
    yeardata = new Ext.data.JsonStore({
        url: Ext.getClassUrl('RecyclingView', 'GetYearTime'),
        root: 'ResponseObject',
        fields: ['yearid', 'yeartext'],
        listeners: {
            beforeload: function (st, op) {
                var re = new JsonRequest();
                re.category = CATEGORY.READONLY;
                st.baseParams = re;
                st.proxy.conn.jsonData = re;
            }
        }
    });


    var ChangeTitle = function () {
        Ext.getCmp("MainTitle").setTitle(Ext.getCmp("year").getValue() + "年" + Ext.getCmp("month").getValue() + "月团柏矿结算分析");
    }
    //数据列表
    var lmsstore = new Ext.data.JsonStore({
        url: Ext.getClassUrl('SettlementView', 'Get_SettlementReportData'),
        root: 'ResponseObject',
        fields: ['队组编码', '队组名称', '工资收入', '材料', '回收', '安全', '租赁', '运输', '加工修理', '后勤服务', '电力', '合计'],
        listeners: {
            beforeload: function (st, op) {
                var re = new JsonRequest();
                re.category = CATEGORY.READONLY;
                re.params.year = Ext.getCmp("year").getValue();
                re.params.month = Ext.getCmp("month").getValue();
                st.baseParams = re;
                st.proxy.conn.jsonData = re;
            }
        }
    });

    var teamStore = new Ext.data.JsonStore({
        data: [
            { name: '工资收入', value: 0 },
            { name: '材料', value: 0 },
            { name: '回收', value: 0 },
            { name: '安全', value: 0 },
            { name: '租赁', value: 0 },
            { name: '运输', value: 0 },
            { name: '加工修理', value: 0 },
            { name: '后勤服务', value: 0 },
            { name: '电力', value: 0 }
        ],
        fields: ['name', 'value']
    });

    function NumFormat(s, m) {
        if (s < 0) m.css = 'redNum';
        //if (s == 0) return '';
        return Ext.util.Format.number(s, '0.00');
    }
    var lmsdatagrid = new Ext.grid.GridPanel({
        autoscroll: true,
        bodyStyle: 'padding:2px',
        border: false,
        loadMask: true, //加载
        columns: [
           { id: '队组编码', header: '队组编码', width: 100, dataIndex: '队组编码', sortable: true },
           { header: '队组名称', width: 100, dataIndex: '队组名称', sortable: true },
           { header: '工资收入', width: 100, dataIndex: '工资收入', sortable: true },
           { header: '材料', width: 100, dataIndex: '材料', sortable: true, renderer: NumFormat },
           { id: '回收', header: '回收', width: 100, dataIndex: '回收', sortable: true, renderer: NumFormat },
           { id: '安全', header: '安全', width: 100, dataIndex: '安全', sortable: true, renderer: NumFormat },
           { id: '租赁', header: '租赁', width: 100, dataIndex: '租赁', sortable: true, renderer: NumFormat },
           { id: '运输', header: '运输', width: 100, dataIndex: '运输', sortable: true, renderer: NumFormat },
           { id: '加工修理', header: '加工修理', width: 100, dataIndex: '加工修理', sortable: true, renderer: NumFormat },
           { id: '后勤服务', header: '后勤服务', width: 100, dataIndex: '后勤服务', sortable: true, renderer: NumFormat },
           { id: '电力', header: '电力', width: 100, dataIndex: '电力', sortable: true, renderer: NumFormat },
           { id: '合计', header: '合计', width: 100, dataIndex: '合计', sortable: true, renderer: NumFormat }
        ],
        store: lmsstore,
        listeners: {
            rowclick: function (g, r) {
                var record = g.getStore().getAt(r);

                Ext.getCmp('piePanel').setTitle('各队组收入比例图 - <b style="color:#000000;font-size:14px;">' + record.get('队组名称') + '</b>');

                teamStore.each(function (trc) {
                    var c = trc.get('name');
                    trc.set('value', record.get(c));
                });
            }
        }
    });
    //布局
    new Ext.Viewport({
        layout: 'border',
        items: [{
            region: 'center',
            layout: 'border',
            border: false,
            id: 'MainTitle',
            title: ' ',
            iconCls: 'ReportTitle-icon',
            tbar: ['日期：', { xtype: 'combo', width: 100, id: 'year',
                typeAhead: true,
                triggerAction: 'all',
                lazyRender: true,
                mode: 'local',
                store: yeardata,
                valueField: 'yearid',
                displayField: 'yeartext',
                listeners: {
                    select: function () {
                        ChangeTitle();
                    }
                }

            }, '年', { xtype: 'combo', width: 70, id: 'month',
                typeAhead: true,
                triggerAction: 'all',
                lazyRender: true,
                mode: 'local',
                store: new Ext.data.ArrayStore({
                    id: 0,
                    fields: [
                            'monthid',
                            'monthtext'
                        ],
                    data: [['01', '01'], ['02', '02'], ['03', '03'], ['04', '04'], ['05', '05'], ['06', '06'], ['07', '07'], ['08', '08'], ['09', '09'], ['10', '10'], ['11', '11'], ['12', '12']]
                }),
                valueField: 'monthid',
                displayField: 'monthtext',
                listeners: {
                    select: function () {
                        ChangeTitle();
                    }
                }
            }, '月', { xtype: 'button', text: '查询', iconCls: 'search-icon', handler: function () {
                lmsstore.removeAll();
                lmsstore.load();
            }
            },'->', '-',
            { xtype: 'button', text: '材料', height: 20, width: 50, iconCls: 'cl-icon', handler: function () { window.open('Reports/Materials.aspx?t=' + Ext.getCmp("year").getValue() + '-' + Ext.getCmp("month").getValue() + '-01', '_parent'); } },
            { xtype: 'button', text: '回收', height: 20, width: 50, iconCls: 'hs-icon', handler: function () { window.open('ReuseRecycle_ZDB/Recycling.aspx?t=' + Ext.getCmp("year").getValue() + '-' + Ext.getCmp("month").getValue() + '-01', '_parent'); } },
            { xtype: 'button', text: '复用', height: 20, width: 50, iconCls: 'fy-icon', handler: function () { window.open('ReuseRecycle_ZDB/Reuse.aspx?t=' + Ext.getCmp("year").getValue() + '-' + Ext.getCmp("month").getValue() + '-01', '_parent'); } },
            { xtype: 'button', text: '安全', height: 20, width: 50, iconCls: 'aq-icon', handler: function () { window.open('EverydayRisks.aspx?t=' + Ext.getCmp("year").getValue() + '-' + Ext.getCmp("month").getValue() + '-01', '_parent'); } },
            { xtype: 'button', text: '租赁', height: 20, width: 50, iconCls: 'zl-icon', handler: function () { window.open('Reports/Rental.aspx?t=' + Ext.getCmp("year").getValue() + '-' + Ext.getCmp("month").getValue() + '-01', '_parent'); } },
            { xtype: 'button', text: '运输', height: 20, width: 50, iconCls: 'ys-icon', handler: function () { window.open('Empty.aspx', '_parent') } },
            { xtype: 'button', text: '加工', height: 20, width: 50, iconCls: 'jg-icon', handler: function () { window.open('Empty.aspx', '_parent') } },
            { xtype: 'button', text: '后勤', height: 20, width: 50, iconCls: 'hq-icon', handler: function () { window.open('Empty.aspx', '_parent') } },
            { xtype: 'button', text: '电力', height: 20, width: 50, iconCls: 'dl-icon', handler: function () { window.open('Empty.aspx', '_parent') } },
            { xtype: 'button', text: '产量收入趋势', height: 20, width: 50, iconCls: 'clsr-icon', handler: function () { window.open('Reports/ProductReport.aspx?t=' + Ext.getCmp("year").getValue() + '-' + Ext.getCmp("month").getValue() + '-01', '_parent'); } },
            { xtype: 'button', text: '设备台帐', height: 20, width: 50, iconCls: 'sbtz-icon', handler: function () { window.open('Reports/Equipment.aspx?t=' + Ext.getCmp("year").getValue() + '-' + Ext.getCmp("month").getValue() + '-01', '_parent'); } },
            '-', '-', { text: '图形报表', iconCls: 'ImgData-icon', handler: function () {
                if (winState == "0") {
                    winState = "2";
                    //Ext.getCmp("piePanel").collapse(true);
                    Ext.getCmp("DataList").collapse(true);
                    Ext.getCmp("ImgDataList").expand(true);
                }
                else {
                    winState = "0";
                    //Ext.getCmp("piePanel").expand(true);
                    Ext.getCmp("DataList").expand(true);
                }
            }
            }],
            items: [{
                region: 'west',
                title: '数据报表',
                iconCls: 'DataList-icon',
                style: 'padding:2px',
                collapsible: true,
                width: 460,
                split: true,
                id: 'DataList',
                layout: 'fit',
                items: lmsdatagrid
            }, {
                region: 'center',
                split: true,
                layout: 'border',
                border: false,
                split: true,
                id: 'ImgCount',
                items: [{
                    region: 'center',
                    title: '图形报表',
                    iconCls: 'ImgDataList-icon',
                    id: 'ImgDataList',
                    style: 'padding-top:2px;padding-right:2px;padding-bottom:2px',
                    xtype: 'tabpanel',
                    activeTab: 0,
                    items: [{
                        title: '全部队组收入表',
                        items: [{
                            xtype: 'columnchart',
                            store: lmsstore,
                            chartStyle: {
                                padding: 10,
                                animationEnabled: true,
                                font: {
                                    name: 'Tahoma',
                                    color: 0x444444,
                                    size: 11
                                },
                                dataTip: {
                                    padding: 5,
                                    border: {
                                        color: 0x99bbe8,
                                        size: 1
                                    },
                                    background: {
                                        color: 0xDAE7F6,
                                        alpha: .9
                                    }
                                },
                                xAxis: {
                                    color: 0x69aBc8,
                                    majorTicks: { color: 0x69aBc8, length: 4 },
                                    minorTicks: { color: 0x69aBc8, length: 2 },
                                    majorGridLines: { size: 1, color: 0xeeeeee },
                                    labelRotation: -90
                                },
                                yAxis: {
                                    zeroGridLine:
	                                {
	                                    size: 2,
	                                    color: 0xff0000
	                                },
                                    color: 0x69aBc8,
                                    majorTicks: { color: 0x69aBc8, length: 4 },
                                    minorTicks: { color: 0x69aBc8, length: 2 },
                                    majorGridLines: { size: 1, color: 0xdfe8f6 }
                                }
                            },
                            xField: '队组名称',
                            yField: '合计',
                            yAxis: new Ext.chart.NumericAxis({
                                displayName: '合计',
                                labelRenderer: Ext.util.Format.numberRenderer('0,0')
                            }),
                            series: [{
                                type: 'column',
                                displayName: '合计',
                                yField: '合计'
                            }, {
                                type: 'line',
                                displayName: '租赁',
                                yField: '租赁',
                                style: {
                                    color: 0xf0f000
                                }
                            }]
                        }]
                    }]
                }, {
                    id: 'piePanel',
                    region: 'south',
                    title: '各队组收入比例图',
                    collapsible: true,
                    split: true,
                    height: 300,
                    iconCls: 'Piechart-icon',
                    style: 'padding:2px;',
                    items: [{
                        id: 'pieChart',
                        store: teamStore,
                        xtype: 'piechart',
                        series: [{
                            categoryField: 'name',
                            dataField: 'value'
                        }],
                        extraStyle: {
                            animationEnabled: true,
                            legend: {
                                display: 'right',
                                padding: 2,
                                font: {
                                    family: 'Tahoma',
                                    size: 11
                                }
                            }
                        }
                    }]
                }]
            }]
        }],
        listeners: {
            render: function () {
                Ext.getCmp("year").setValue(YearT);
                Ext.getCmp("month").setValue(MonthT);
                ChangeTitle();
                yeardata.load();
                //lmsstore.load();
            },
            afterrender: function () {
                lmsstore.load();
            }
        }
    })
});


